import { ETaskState } from "GameLoop/DecisionMaking/TaskDeclare/type";
import { ATaskAdapter } from ".";
import { BoostState } from "GameLoop/WorldState/EntityManager/Entitys/room/lab/types";

export class BoostTaskAdapter extends ATaskAdapter<"boost">
{

 
    public bindTasks(room: Room, tasks:ITaskDeclare["boost"][],customCheck:IConditionFunction): void 
    {
        const labEntity = room.getEntity("LabEntity");
     
        const memory = labEntity.getNodeMemory();
        memory.boostTasks = memory.boostTasks.filter(e=>room.findTaskById(e,"boost"));
        for(const task of tasks)
        {
            if(customCheck(room as Required<Room>,task) == OK )
            {
                room.deleteTaskById(task.id,"boost");
                continue;
            }
            if(ETaskState.Complete == this.checkState(room,task))
            {
                //global.Log.Info(`${room.name} room ${task.id} check 已经完成`);
                room.deleteTaskById(task.id,"boost");
                continue;
            }
           // global.Log.Info(`${room.name} room ${task.id} check 未完成`);
        }
        if(room.canExecute(14237) && memory.boostTasks.length==0)
        {
            labEntity.resetLabState();
        }
    }

    protected checkState(room:Room,task:ITaskDeclare["boost"]):ETaskState
    {
       
        const labEntity = room.getEntity("LabEntity");
      
        if(!Game.creeps[task.id])
        {
            global.Log.Warning(`boost 任务错误 要强化的爬为undefined ${JSON.stringify(task)}`);
            return ETaskState.Complete;
        }
        if(Game.creeps[task.id].memory.IsBoosted)
        {
            return ETaskState.Complete;
        }
        if(task.data.arg.State== BoostState.complete)
        {
            return ETaskState.Complete;
        }
        
        labEntity.activeBoostTask(task);
        return ETaskState.Running;
    }
    
}